/**
 * 
 */


var TerminalForm = {
	init: function(){
		TerminalForm.initEvent();
		this.bind();
	},
	initEvent: function(){
		$('.date-alarm-ul li').bind('click',function(i){
			if($(this).index()==0){
				$('.date-alarm').css('left','0px');
				$("#baseInfoDiv").show();
				$("#otherInfoDiv").hide();
			}else{
				$('.line').css('left','100px');
				$("#baseInfoDiv").hide();
				$("#otherInfoDiv").show();
			}
		});
	},
	
	bind : function(){
		$('body').on('click','#addTerminalPanel',function(){
			
			if ($('#workUnitId').val() == '') {
				showVelidateModal('请选择企业');
				return;
			}
			$("#terminal_UnitID").val($('#workUnitId').val());
			$("#terminal_UnitName").val($('#workUnitId').combotree("getText"));
			$("#terminal_SimNo").focus();
			TerminalForm.initPanel();
			$('.TerminalPanel').show();
			
		});
		
		$('body').on('click','.TerminalPanel .close',function(){
			$('.TerminalPanel').hide();
		});
		
		$('body').on('click','#ClearTerminal',function(){
			$("#terminal_SimNo").val('');
			$("#terminal_ComNo").val('');
			$("#terminal_TerminalTypeID").combobox("setValue","");
		});
		
		$("#addTerminal").click(function(){
			TerminalForm.addTerminal()
		});
		
	},
savePubTerminal:function(){
	if(action=='update'){
		if(!checkparam()){
			return;
		}
		// 保存运政机构
		$.ajax({
			type : 'post',
			url : appCtx + "base/PubTerminal/updatePubTerminal.html",
			data : $("#vehicleForm").serialize(),
			cache : false,
			dataType : "JSON",
			success : function(data) {
				if (data.code == "0") {
					global.ajaxLoading.pop('操作成功!',false,800);
					var funStr = "window.frames['" + mFrameName + "']."+ mDialogCallback;
					eval("(" + funStr + ")");
					closeDataDialog();
				}else {
					closeDataDialog();
					showVelidateModal("操作失败!");
					return;
				}
			}
		});
	}
	if(action=='save'){
		if(!checkparam()){
			return;
		}
		// 保存运政机构
		$.ajax({
			type : 'post',
			url : appCtx + "base/PubTerminal/addPubterminal.html",
			data : $("#vehicleForm").serialize(),
			cache : false,
			dataType : "JSON",
			success : function(data) {
				if (data.code == "0") {
					global.ajaxLoading.pop(data.msg,false,2000);
					var funStr = "window.frames['" + mFrameName + "']."+ mDialogCallback;
					eval("(" + funStr + ")");
					closeDataDialog();
				}else {
					global.ajaxLoading.pop(data.msg,false,2000);
					return;
				}
			}
		});
	}
}
};
TerminalForm.init();
/**
 * 检查新增运政机构参数
 */
function checkparam(){
	var name = $("#name").val();
	var applyKind = $("#applyKind").val();
	var locationModule = $("#locationModule").val();
	var commMode = $("#commMode").val();
	var venderName = $("#venderName").val();
	var venderCode = $("#venderCode").val();
	if(name==null||name==''){
		global.ajaxLoading.pop('请填写设备型号',false,1000);
		return false;
	}
	if(applyKind==null||applyKind==''){
		global.ajaxLoading.pop('请填写适用车型',false,1000);
		return false;
	}
	if(locationModule==null||locationModule==''){
		global.ajaxLoading.pop('请填写定位模块',false,1000);
		return false;
	}
	if(commMode==null||commMode==''){
		global.ajaxLoading.pop('请填写通讯模式',false,1000);
		return false;
	}
	if(venderName==null||venderName==''){
		global.ajaxLoading.pop('请填写厂家名称',false,1000);
		return false;
	}
	if(venderCode==null||venderCode==''){
		global.ajaxLoading.pop('请填写厂家编号',false,1000);
		return false;
	}
	return true;
}

